home *** CD-ROM | disk | FTP | other *** search
- #include <SWIncludes.h>
- #include "Shark Attack.h"
- #include "NewSprite.h"
- #include "Level.h"
- #include "SpriteMoveProcs.h"
- #include "SpriteCollideProcs.h"
- #include "SWSounds.h"
- #include "GlobalVariables.h"
-
-
- #define kFishHitMoveDelay 4 // How many frames to delay a fish that was hit
- #define kSharkHitMoveDelay 5 // How many frames to delay a shark that was hit
-
- #define kFishKilledScore 25
- #define kSharkKilledScore 50
- #define kFishHitScore 1
- #define kSharkHitScore 2
-
- #define kFlashWhiteTime 2 // How many frames a fish stays white when hit
-
-
- ///--------------------------------------------------------------------------------------
- // SubSpriteCollideProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SubSpriteCollideProc(
- SpritePtr subSpriteP,
- SpritePtr fishSpriteP,
- Rect* sectRect)
- {
- #pragma unused(sectRect) // Tell CodeWarrior this variable is unused
- short oldFPSValue, stereoPos;
- Boolean hasCollided;
-
- // See if the actual sprite images collided
- if (gSpriteWorldP->pixelDepth == 8)
- hasCollided = SWPixelCollision(subSpriteP, fishSpriteP); // Faster, but 8-bit only
- else
- hasCollided = SWRegionCollision(subSpriteP, fishSpriteP); // Works in any depth
-
- if (hasCollided)
- {
- stereoPos = GetStereoPositionOfSprite(subSpriteP, &gSpriteWorldP->backRect);
- PlaySound2(kSubDeadSnd, 2, kFindEmptyChannel, 256, stereoPos, k22khz, false);
-
- // Make all the sprites stop moving
- PauseSprites();
-
- // Make the submarine sink to the bottom of the screen
- SWSetSpriteMoveProc(subSpriteP, DeadSubSpriteMoveProc);
- ((SubStructPtr)subSpriteP)->vertDelta = 0;
-
- // Allow the sub to sink smoothly & quickly to the bottom of the screen
- oldFPSValue = gSpriteWorldP->fpsTimeInterval;
- SWSetSpriteWorldMaxFPS(gSpriteWorldP, 90);
-
- gSubIsStillOnScreen = true;
- while (gSubIsStillOnScreen)
- {
- SWProcessSpriteWorld(gSpriteWorldP);
- SWAnimateSpriteWorld(gSpriteWorldP);
- }
-
- UnpauseSprites(); // Unpause the SpriteLayers that were paused
-
- // Restore the original fps value
- gSpriteWorldP->fpsTimeInterval = oldFPSValue;
-
- gNumLivesLeft--;
- if (gNumLivesLeft < 0)
- {
- DoGameOver();
- gGameOver = true;
- }
- else
- {
- RestartLevel();
- }
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // FishSpriteCollideProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void FishSpriteCollideProc(
- SpritePtr fishSpriteP,
- SpritePtr bulletSpriteP,
- Rect* sectRect)
- {
- #pragma unused(sectRect) // Tell CodeWarrior this variable is unused
- Boolean hasCollided;
- short stereoPos;
- FishStructPtr fishStructP = (FishStructPtr)fishSpriteP;
-
- // See if the actual sprite images collided
- if (gSpriteWorldP->pixelDepth == 8)
- hasCollided = SWPixelCollision(bulletSpriteP, fishSpriteP); // Faster, but 8-bit only
- else
- hasCollided = SWRegionCollision(bulletSpriteP, fishSpriteP); // Works in any depth
-
-
- if (hasCollided)
- {
- // Remove the bullet
- ((BulletStructPtr)bulletSpriteP)->parentStructP->numBulletsOnScreen--;
- SWRemoveSpriteFromAnimation(gSpriteWorldP, bulletSpriteP, true);
- if (bulletSpriteP == gLastBulletP)
- gLastBulletP = NULL;
-
- fishStructP->energy--;
-
- // Remove the fish if all energy is gone
- if ( fishStructP->energy <= 0)
- {
- stereoPos = GetStereoPositionOfSprite(fishSpriteP, &gSpriteWorldP->backRect);
- PlaySound2(kFishDeadSnd, 0, kFindEmptyChannel, 256, stereoPos, k22khz, false);
- gScore += kFishKilledScore;
- gNumFishOnScreen--;
- SWRemoveSpriteFromAnimation(gSpriteWorldP, fishSpriteP, true);
- }
- else
- {
- stereoPos = GetStereoPositionOfSprite(fishSpriteP, &gSpriteWorldP->backRect);
- PlaySound2(kHitFishSnd, 2, kFindEmptyChannel, 256, stereoPos, k22khz, false);
-
- gScore += kFishHitScore;
-
- // Make the fish pause temporarily because it was hit
- fishStructP->moveDelay = kFishHitMoveDelay;
-
- // Make the fish flash white
- fishStructP->hitCounter = kFlashWhiteTime;
- fishSpriteP->needsToBeDrawn = true;
- SWSetSpriteDrawProc(fishSpriteP, FishHitDrawProc);
- }
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SharkSpriteCollideProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SharkSpriteCollideProc(
- SpritePtr sharkSpriteP,
- SpritePtr bulletSpriteP,
- Rect* sectRect)
- {
- #pragma unused(sectRect) // Tell CodeWarrior this variable is unused
- Boolean hasCollided;
- short stereoPos;
- SharkStructPtr sharkStructP = (SharkStructPtr)sharkSpriteP;
-
- // See if the actual sprite images collided
- if (gSpriteWorldP->pixelDepth == 8)
- hasCollided = SWPixelCollision(bulletSpriteP, sharkSpriteP); // Faster, but 8-bit only
- else
- hasCollided = SWRegionCollision(bulletSpriteP, sharkSpriteP); // Works in any depth
-
-
- if (hasCollided)
- {
- // Remove the bullet
- ((BulletStructPtr)bulletSpriteP)->parentStructP->numBulletsOnScreen--;
- SWRemoveSpriteFromAnimation(gSpriteWorldP, bulletSpriteP, true);
- if (bulletSpriteP == gLastBulletP)
- gLastBulletP = NULL;
-
- sharkStructP->energy--;
-
- // Remove the shark if all energy is gone
- if ( sharkStructP->energy <= 0)
- {
- stereoPos = GetStereoPositionOfSprite(sharkSpriteP, &gSpriteWorldP->backRect);
- PlaySound2(kSharkDeadSnd, 1, kFindEmptyChannel, 256, stereoPos, k22khz, false);
- gScore += kSharkKilledScore;
- gNumSharksOnScreen--;
- SWRemoveSpriteFromAnimation(gSpriteWorldP, sharkSpriteP, true);
- }
- else
- {
- stereoPos = GetStereoPositionOfSprite(sharkSpriteP, &gSpriteWorldP->backRect);
- PlaySound2(kHitSharkSnd, 2, kFindEmptyChannel, 256, stereoPos, k22khz, false);
- gScore += kSharkHitScore;
-
- /// Make the shark pause temporarily because it was hit
- sharkStructP->moveDelay = kSharkHitMoveDelay;
-
- // Make the shark flash white
- sharkStructP->hitCounter = kFlashWhiteTime;
- sharkSpriteP->needsToBeDrawn = true;
- SWSetSpriteDrawProc(sharkSpriteP, FishHitDrawProc);
- }
- }
- }
-
-